
from fastapi import APIRouter, Depends

from src.server.crawler_task import CrawlerTaskServer
from src.model import ResponseModel
from src.model.request import CrawlerRequest
from src.dependencies import verify_token

router = APIRouter(dependencies=[Depends(verify_token)])

def get_crawler_server():
    return CrawlerTaskServer()

@router.post("/create_crawler",response_model=ResponseModel)
async def create_crawler(request:CrawlerRequest,server:CrawlerTaskServer = Depends(get_crawler_server)):
    return server.create(request)


@router.get("/run_crawler",response_model=ResponseModel)
async def run_crawler(crawler_id:str,server:CrawlerTaskServer = Depends(get_crawler_server)):
    return server.run(crawler_id)

@router.get("/delete_crawler", response_model=ResponseModel)
async def delete_crawler(crawler_id: str,server:CrawlerTaskServer = Depends(get_crawler_server)):
    return server.delete(crawler_id)


@router.get("/get_crawler_result", response_model=ResponseModel)
async def get_crawler_result(crawler_id: str,server:CrawlerTaskServer = Depends(get_crawler_server)):
    return await server.get_result(crawler_id)



